<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="团队名称">
              <j-input placeholder="请输入团队名称" v-model="queryParam.tdmc"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="团队类别">
              <j-dict-select-tag placeholder="请选择团队类别" v-model="queryParam.teamType" dictCode="team_type" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号">
              <j-input placeholder="请输入单据编号" v-model="queryParam.tdbh"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="团队类型">
              <j-dict-select-tag placeholder="请选择团队类型" v-model="queryParam.tdlx" dictCode="tdlx_type" />
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业务类型">
              <j-dict-select-tag
                type="list"
                v-model="queryParam.businessType"
                dictCode="erp_files_business_category,category_name,id,level='1'"
                placeholder="请选择业务类型" />
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpOmcTeamManager:add')">新增
      </a-button>
      <a-button
        @click="handleSync"
        type="primary"
        icon="plus"
        v-has="'erpOmcTeamManager:sync'"
        :disabled="isDisabledAuth('erpOmcTeamManager:sync')">同步团队
      </a-button>
      <!--      <a-button type="primary" icon="download" @click="handleExportXls('团队管理')"-->
      <!--                :disabled="isDisabledAuth('erpOmcTeamManager:export')">导出-->
      <!--      </a-button>-->
      <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"-->
      <!--                @change="handleImportExcel">-->
      <!--        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpOmcTeamManager:import')">导入</a-button>-->
      <!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpOmcTeamManager:delete')">
            <a-icon type="delete" />
            删除
          </a-menu-item>
          <a-menu-item key="2" @click="batchSubmit" :disabled="isDisabledAuth('erpOmcTeamManager:submit')">
            <a-icon type="to-top" />
            提交
          </a-menu-item>
          <a-menu-item key="3" @click="batchAudit" :disabled="isDisabledAuth('erpOmcTeamManager:audit')">
            <a-icon type="audit" />
            审核
          </a-menu-item>
          <a-menu-item key="4" @click="batchCounterTrial" :disabled="isDisabledAuth('erpOmcTeamManager:counterTrial')">
            <a-icon type="rollback" />
            反审
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle" />
        </a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, getCheckboxProps: (record) => { return { props: { disabled: record.auditStatus !== 0 } } }}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        :indentSize="35"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter" />
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <template v-if="record.auditStatus==0">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpOmcTeamManager:edit')" />
            <a-divider type="vertical" />
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="delete"
                :disabled="isDisabledAuth('erpOmcTeamManager:delete')" />
            </a-popconfirm>
            <a-divider type="vertical" />

            <a-popconfirm title="确定提交吗?" @confirm="() => handleSubmit(record.id)">
              <a-button type="primary" size="small" :disabled="isDisabledAuth('erpOmcTeamManager:submit')">提交</a-button>
            </a-popconfirm>
          </template>
          <template v-if="record.auditStatus==1">
            <a-button
              type="primary"
              size="small"
              @click="handleAudit(record.id)"
              :disabled="isDisabledAuth('erpOmcTeamManager:audit')">审核</a-button>
          </template>
          <template v-if="record.auditStatus==2">
            <a-popconfirm title="确定反审吗?" @confirm="() => handleCounterTrial(record.id)">
              <a-button
                type="primary"
                size="small"
                :disabled="isDisabledAuth('erpOmcTeamManager:counterTrial')">反审</a-button>
            </a-popconfirm>
          </template>
          <a-divider type="vertical" />
          <template v-if="record.auditStatus==2">
            <a-button
              @click="toAdd(record.id)"
              type="primary"
              size="small"
              :disabled="isDisabledAuth('erpOmcTeamManager:add')">添加下级</a-button>
          </template>
        </span>
      </a-table>
    </div>
    <erp-omc-team-manager-modal ref="modalForm" @ok="modalFormOk"></erp-omc-team-manager-modal>
    <audit-modal ref="auditModal" @ok="modalFormOk"></audit-modal>
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpOmcTeamManagerModal from './modules/ErpOmcTeamManagerModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import { getAction } from '@/api/manage'
export default {
  name: 'ErpOmcTeamManagerList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpOmcTeamManagerModal,
    SelectUserByDep
  },
  data() {
    return {
      description: '团队管理管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '单据编号',
          dataIndex: 'tdbh',
          customRender: (value, row, index) => {
            const obj = {
              children: value,
              attrs: {}
            };
            obj.attrs.align = 'left';// 控制表体内容居右
            return obj;
          },
          width: 164,
          ellipsis: true
        },
        {
          title: '团队类型',
          align: 'center',
          dataIndex: 'tdlx_dictText',
          width: 158,
          ellipsis: true
        },
        {
          title: '业务类型',
          align: 'center',
          dataIndex: 'businessType_dictText',
          width: 300,
          ellipsis: true
        },
        {
          title: '团队名称',
          align: 'center',
          dataIndex: 'tdmc',
          width: 338,
          ellipsis: true
        },
        {
          title: '管理机构负责人',
          align: 'center',
          dataIndex: 'institutionManager_dictText',
          width: 104,
          ellipsis: true
        },
        {
          title: '团队负责人',
          align: 'center',
          dataIndex: 'tdfzr_dictText',
          width: 104,
          ellipsis: true
        },
        {
          title: '团队分管负责人',
          align: 'center',
          dataIndex: 'tdfg_dictText',
          width: 120,
          ellipsis: true
        },
        {
          title: '审核状态',
          align: 'center',
          dataIndex: 'auditStatus',
          scopedSlots: { customRender: 'status' },
          width: 150,
          filterMultiple: false,
          filters: [
            {
              text: '待提交',
              value: 0
            }, {
              text: '待审核',
              value: 1
            }, {
              text: '已审核',
              value: 2
            }]
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      url: {
        list: '/api/erp/omc/teammanager/erpOmcTeamManager/list',
        sync: '/api/erp/omc/teammanager/erpOmcTeamManager/syncTeamCode',
        delete: '/api/erp/omc/teammanager/erpOmcTeamManager/delete',
        deleteBatch: '/api/erp/omc/teammanager/erpOmcTeamManager/deleteBatch',
        exportXlsUrl: '/api/erp/omc/teammanager/erpOmcTeamManager/exportXls',
        importExcelUrl: 'api/erp/omc/teammanager/erpOmcTeamManager/importExcel',
        submit: '/api/erp/omc/teammanager/erpOmcTeamManager/submit',
        submitBatch: '/api/erp/omc/teammanager/erpOmcTeamManager/submitBatch',
        revoke: '/api/erp/omc/teammanager/erpOmcTeamManager/revoke',
        revokeBatch: '/api/erp/omc/teammanager/erpOmcTeamManager/revokeBatch',
        counterTrial: '/api/erp/omc/teammanager/erpOmcTeamManager/counterTrial',
        stop: '/api/erp/omc/teammanager/erpOmcTeamManager/stop',
        counterTrialBatch: '/api/erp/omc/teammanager/erpOmcTeamManager/counterTrialBatch',
        audit: '/api/erp/omc/teammanager/erpOmcTeamManager/audit',
        auditBatch: '/api/erp/omc/teammanager/erpOmcTeamManager/auditBatch',
        overrule: '/api/erp/omc/teammanager/erpOmcTeamManager/overrule',
        overruleBatch: '/api/erp/omc/teammanager/erpOmcTeamManager/overruleBatch'
      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    toAdd(parentId) {
      this.$refs.modalForm.add(parentId)
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'tdbh', text: '单据编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tdnd', text: '团队年度', dictCode: 'tdnd_type' })
      fieldList.push({ type: 'string', value: 'tdmc', text: '团队名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'tdlx', text: '团队类型', dictCode: 'tdlx_type' })
      fieldList.push({ type: 'string', value: 'tdfzr', text: '团队负责人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tdfg', text: '团队分管', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmb', text: '项目部', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sys', text: '实验室', dictCode: '' })
      fieldList.push({ type: 'string', value: 'zhjs', text: '综合技术', dictCode: '' })
      fieldList.push({ type: 'int', value: 'zjje', text: '资金金额(元)', dictCode: '' })
      fieldList.push({ type: 'int', value: 'byj', text: '备用金(元)', dictCode: '' })
      fieldList.push({ type: 'int', value: 'yrje', text: '预入金额(元)', dictCode: '' })
      fieldList.push({ type: 'int', value: 'yyje', text: '已用金额(元)', dictCode: '' })
      fieldList.push({ type: 'int', value: 'ytje', text: '预提金额(元)', dictCode: '' })
      fieldList.push({ type: 'int', value: 'kyje', text: '可用金额(元)', dictCode: '' })
      fieldList.push({ type: 'int', value: 'syje', text: '剩余金额(元)', dictCode: '' })
      fieldList.push({ type: 'int', value: 'ljhtbgje', text: '累计报告合同金额(元)', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sjlrbl', text: '上缴利润比例', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sjglfbl', text: '上缴管理费比例', dictCode: '' })
      fieldList.push({ type: 'int', value: 'ggyw', text: '公共业务', dictCode: 'yn' })
      fieldList.push({ type: 'int', value: 'zt', text: '状态', dictCode: 'status_type' })
      fieldList.push({ type: 'int', value: 'auditStatus', text: '状态', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleSync() {
      getAction(this.url.sync, null).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.warning(res.message)
        }
      })
    },

    handleStop: function (id, zt) {
      if (!this.url.counterTrial) {
        this.$message.error('请设置url.counterTrial属性!')
        return
      }
      var that = this
      getAction(that.url.stop, {
        id: id,
        zt: zt
      }).then(res => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
  @import '~@assets/less/common.less';
  /deep/.ant-table-thead > tr > th {
    text-align: center;
  }
</style>
